import axios from "axios";
import { Toast } from "vant";

const baseURL = "https://qcljo8.api.cloudendpoint.cn";
// 创建 axios 实例
const service = axios.create({
  baseURL: baseURL, // api base_url
  timeout: 60000, // 请求超时时间
});

service.CancelToken = axios.CancelToken

// 错误结果拦截器
const err = error => {
  if (!axios.isCancel(error)) {
    Toast.fail("请求失败");
    return Promise.reject(error);
  }
};

// 结果拦截器
service.interceptors.response.use(response => {
  if (response.status === 200) {
    return response.data;
  }
}, err);

export { service as axios };
